from apps.common.base.serializers import *
from apps.education.courseEvaluate.models import *
from apps.education.student.serializers import StudentBaseSerializer
from apps.education.teacher.serializers import TeacherBaseSerializer

class CourseEvaluateBaseSerializer(BaseSerializer):
    class Meta:
        model = CourseEvaluate
        fields = "__all__"


class CourseEvaluateModelSerializer(CourseEvaluateBaseSerializer):

    userModel = serializers.SerializerMethodField()
    def get_userModel(self, obj):
        if obj.user.role.key == 'student':
            return StudentBaseSerializer(obj.user.user_student.first()).data
        elif obj.user.role.key == 'teacher':
            return TeacherBaseSerializer(obj.user.user_teacher.first()).data
        else:
            return {}
        
    class Meta:
        model = CourseEvaluate
        fields = "__all__"
